<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>    
    <meta charset="UTF-8">
       
    <meta name="viewport" content="width=device-width, initial-scale=1, maximumscale=1">
       <title>Title</title>    
    <link rel="stylesheet" href="resources/layui/css/layui.css" media="all"/>
</head>
<body>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script th:inline="none">
    //Demo
    layui.use(['layer', 'form', 'table'], function () {
        var layer = layui.layer
            , form = layui.form
            , table = layui.table
            , $ = layui.jquery;//引入jquery

//        //监听提交
//        form.on('submit(formDemo)', function(data){
//            layer.msg(JSON.stringify(data.field));
//            return false;
//        });
        $("#from1").click(function (){
            layer.msg("$$$$$$$")
            $.ajax({
                type: "GET",//方法类型
                dataType: "json",//预期服务器返回的数据类型
                url: "/troublerecord/addtroublerecord" ,//url
                data: $('#from2').serialize(),
                success: function (res) {
                    console.log(res);//打印服务端返回的数据(调试用)
                    if (res.code==512) {
                        layer.msg(res.message);
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index);
                    }else if(res.code==511){
                        layer.msg(res.message);
                    }
                    ;
                },
            });
        });
        $.ajax({
            type: "GET",
            url: "/vehiclefiles/selectVehicleAll",
            success: function (res) {
                var vehiclefiles = res.data.vehiclefilesList;
                if (vehiclefiles.length > 0) {
                    for (var i = 0; i < vehiclefiles.length; i++) {
                        var vehiclefile = vehiclefiles[i];
                        //追加，注意有坑，需要渲染下拉菜单
                        $("#vehiclenum").append("<option value='" + vehiclefile.id + "'>" + vehiclefile.vehiclenum + "</option>")
                    }
                }
                //渲染下拉菜单
                layui.form.render("select");
            }
        })
        $.ajax({
            type: "GET",
            url: "/driver/selectAllDriver",
            success: function (res) {
                var drivers = res.data.drivers;
                if (drivers.length > 0) {
                    for (var i = 0; i < drivers.length; i++) {
                        var driver = drivers[i];
                        //追加，注意有坑，需要渲染下拉菜单
                        $("#driverid").append("<option value='" + driver.id + "'>" + driver.name + "</option>")
                    }
                }
                //渲染下拉菜单
                layui.form.render("select");
            }
        })


    });
</script>

<form class="layui-form" action="" method="" id="from2">


    <div class="layui-form-item">
        <label class="layui-form-label">车牌号码</label>
        <div class="layui-input-block">
            <select lay-verify="required"  name="vid" id="vehiclenum">
                <option value="0">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">驾驶员</label>
        <div class="layui-input-block">
            <select lay-verify="required" id="driverid" name="driverid">
                <option value="0">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">事故时间</label>
        <div class="layui-input-block">
            <input type="date" name="time" required  lay-verify="required" placeholder="请输入违章时间"  class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">事故地点</label>
        <div class="layui-input-block">
            <input type="text" name="address" required  lay-verify="required" placeholder="填写地点"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">事故原因</label>
        <div class="layui-input-block">
            <input type="text" name="reason" required  lay-verify="required" placeholder="填写事故原因"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">我方情况</label>
        <div class="layui-input-block">
            <input type="text" name="oursitu" required  lay-verify="required" placeholder="情况"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">对方情况</label>
        <div class="layui-input-block">
            <input type="text" name="othersitu" required  lay-verify="required" placeholder="情况"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">处理结果</label>
        <div class="layui-input-block">
            <input type="text" name="result" required  lay-verify="required" placeholder="填写处理结果"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">我方承担金额</label>
        <div class="layui-input-block">
            <input type="text" name="ourmoney" required  lay-verify="required" placeholder="金额"  class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">对方承担金额</label>
        <div class="layui-input-block">
            <input type="text" name="othermoney" required  lay-verify="required" placeholder="金额"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">保险承担金额</label>
        <div class="layui-input-block">
            <input type="text" name="insuremoney" required  lay-verify="required" placeholder="金额"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">事故备注</label>
        <div class="layui-input-block">
            <input type="text" name="information" required  lay-verify="required" placeholder=""  class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="button" class="layui-btn" lay-submit lay-filter="formDemo" id="from1" value="立即提交">
            <!--<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>-->
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>


</body>
</html>